;【AHK2】
; http://cenalulu.github.io/images/linux/vim_cheatsheet/classic.gif
; http://ahkv2.mallocx.com/Tutorial.htm
; https://www.autohotkey.com/boards/viewforum.php?f=82&start=25
; Hotkey Resource: https://www.autohotkey.com/docs/v1/Hotkeys.htm#Symbols
; Symbol Legend - [#, ^, !, +] are modifiers
; # = Windows Key
; ^ = Ctrl
; ! = Alt
; + = Shift


;系统快捷键
;=====================================================================o
;                    CapsLock Direction Navigator                    
;-----------------------------------o---------------------------------o
;      键\修饰    	✱	     !(+)	      ^         ^!
;        h         ←         选字        跳词      跳选词
;        j         ↓         选字        跳词      跳选词
;        k         ↑         选字        跳词      跳选词
;        l         →         选字        跳词      跳选词
;-----------------------------------o---------------------------------o
CapsLock & h:: 
{
    if GetKeyState("control") = 0 
    { 
        if GetKeyState("Alt") = 0 
            ; 无 左移一字
            Send "{Left}" 
        else 
            ; ! 左选一字
            Send "+{Left}" 
        return 
    } 
    else { 
        ; ^ 左跳一词
        if GetKeyState("Alt") = 0 
            Send "^{Left}" 
        else 
        ; ^! 左跳选一词
            Send "+^{Left}" 
        return 
    } 
} 


CapsLock & j:: 
{
    if GetKeyState("control") = 0 
    { 
        if GetKeyState("Alt") = 0 
            Send "{Down}" 
        else 
            Send "+{Down}" 
        return 
    } 
    else { 
        if GetKeyState("Alt") = 0 
            Send "^{Down}" 
        else 
            Send "+^{Down}" 
        return 
    } 
} 

CapsLock & k:: 
{
    if GetKeyState("control") = 0 
    { 
        if GetKeyState("Alt") = 0 
            Send "{Up}" 
        else 
            Send "+{Up}" 
        return 
    } 
    else { 
        if GetKeyState("Alt") = 0 
            Send "^{Up}" 
        else 
            Send "+^{Up}" 
        return 
    } 
} 

CapsLock & l:: 
{
    if GetKeyState("control") = 0 
    { 
        if GetKeyState("Alt") = 0 
            Send "{Right}" 
        else 
            Send "+{Right}" 
        return 
    } 
    else { 
        if GetKeyState("Alt") = 0 
            Send "^{Right}" 
        else 
            Send "+^{Right}" 
        return 
    } 
} 


;=====================================================================o
;                     CapsLock Home/End Navigator                    
;-----------------------------------o---------------------------------o
;                      CapsLock + i |  Home                          
;                      CapsLock + o |  End                           
;                      Ctrl, Alt Compatible                          
;-----------------------------------o---------------------------------o
CapsLock & i:: 
{
    if GetKeyState("control") = 0 
    { 
        if GetKeyState("Alt") = 0 
            Send "{Home}" 
        else 
            Send "+{Home}" 
        return 
    } 
    else { 
        if GetKeyState("Alt") = 0 
            Send "^{Home}" 
        else 
            Send "+^{Home}" 
        return 
    } 
} 

CapsLock & o:: 
{
    if GetKeyState("control") = 0 
    { 
        if GetKeyState("Alt") = 0 
            Send "{End}" 
        else 
            Send "+{End}" 
        return 
    } 
    else { 
        if GetKeyState("Alt") = 0 
            Send "^{End}" 
        else 
            Send "+^{End}" 
        return 
    } 
} 


;=====================================================================o
;                      CapsLock Page Navigator                       
;-----------------------------------o---------------------------------o
;                      CapsLock + u |  PageUp                        
;                      CapsLock + p |  PageDown                      
;                      Ctrl, Alt Compatible                          
;-----------------------------------o---------------------------------o
CapsLock & u:: 
{
    if GetKeyState("control") = 0 
    { 
        if GetKeyState("Alt") = 0 
            Send "{PgUp}" 
        else 
            Send "+{PgUp}" 
        return 
    } 
    else { 
        if GetKeyState("Alt") = 0 
            Send "^{PgUp}" 
        else 
            Send "+^{PgUp}" 
        return 
    } 
} 

CapsLock & p:: 
{
    if GetKeyState("control") = 0 
    { 
        if GetKeyState("Alt") = 0 
            Send "{PgDn}" 
        else 
            Send "+{PgDn}" 
        return 
    } 
    else { 
        if GetKeyState("Alt") = 0 
            Send "^{PgDn}" 
        else 
            Send "+^{PgDn}" 
        return 
    } 
} 

CapsLock & backspace::{
static count:=0
if count>0{
    count++
    return
}
count:=1
settimer after, -400
after(){
    if count=1{
        send "{del}"
    }
    else if count=2{
         send "^{del}"
    }
    else if count=3{
         send "{home}+{end}{del}"
    }   
    else if count>3{
        tooltip count
    }
    count:=0
}
}

CapsLock & s::
{
    if GetKeyState("Ctrl") or GetKeyState("Alt") = 1
        Send "^+{Tab}"
    else
        Send "^{Tab}"
}

CapsLock & q::
{
    if GetKeyState("Alt") = 0
        Send "^{F4}"
    else
        Send "!{F4}"
}

; close Tab
CapsLock & w:: {
    Send "{Blind}^w"
}


;置顶当前窗口
CapsLock & t::
{
	WinSetAlwaysOnTop -1, "A"
	ToolTip "Caps+t to stick the window or cancel it."
}

ToolTip "CapsLock toolkit starts in 5s."
SetTimer () => ToolTip(), -5000


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Obsidian 快捷键
#HotIf winactive("ahk_exe Obsidian.exe")
^!c::MsgBox "You pressed Control+Alt+C in Notepad."
^5:: send  "{end}~~{home}~~{end}" ;删除线
^6:: send "{home}{del}{del}{end}{backspace}{backspace}" ;取消删除线
#HotIf

;判断是否使用notepad2程序
#n::
{
    if WinExist("ahk_class Notepad2")
        WinActivate  ; Activate the window found above
    else
        Run "notepad"  ; Open a new Notepad window
}



;未来要做成函数
app_hotkey(keyname, app_title, app_path)
{
    activate(keyname)  ; This will be a closure due to app_title and app_path.
    {
        if WinExist(app_title)
            WinActivate
        else
            Run app_path
    }
    Hotkey keyname, activate
}
; Win+N activates or launches Notepad.
app_hotkey "#n", "ahk_class Notepad", "notepad.exe"
; Win+W activates or launches WordPad.
app_hotkey "#w", "ahk_class WordPadClass", "wordpad.exe"


Hotkey "^!z", MyFunc
MyFunc(ThisHotkey)
{
    MsgBox "You pressed " ThisHotkey
}
a := "abc"
b := 100
c := "def"
d := 123.456
e := 200

; f 的值是字符串 abc100anddef123.456
f := a b "and" c d
; g 的值是字符串 100200
g := b e